
$(function(){
    "use strict";
    // 点击出现搜索框
    $('.hidden_box_showBox').click(function(){
        $(this).siblings('.hidden_box_hiddenBox').toggleClass('active')
        if($(this).children('i').hasClass('icon-jiantou')){
            $(this).children('i').removeClass('icon-jiantou').addClass('icon-jiantou-top')
            let html = '';
            $.ajax({
                url:'http://jk.com/Admin/Org/showDep',
                type:'get',
                success:function(data){
                    for(var i=0;i<data.length;i++){
                        html += `
                                <option value="${data[i].id}">${data[i].dep_name}</option>
                            `
                    }
                    $('.hidden_box_hiddenBox').find('select[data-query="departMent"]').html(html)
                }
            })
        }else{
            $(this).children('i').removeClass('icon-jiantou-top').addClass('icon-jiantou')
        }
    })
    // 当确定搜索时
    $('.hiddenBox_list_btn').on('click','button',function(){
        $('.hidden_box_hiddenBox').removeClass('active')
        $('.hidden_box_showBox').children('i').removeClass('icon-jiantou-top').addClass('icon-jiantou')
        if($(this).html() == '确定'){
            $('#dateVal').html(window.query_time||'全部')
            let startTime = window.query_time_start
            let endTime = window.query_time_end
            let name = $(this).closest('.hidden_box_hiddenBox').find('[data-query="name"]').val()
            let workNum = $(this).closest('.hidden_box_hiddenBox').find('[data-query="workNum"]').val()
            let departMent = $(this).closest('.hidden_box_hiddenBox').find('[data-query="departMent"]').val()
            window.location.href = `http://jk.com/Admin/Pay/index?start_time=${startTime}&end_time=${endTime}&staff_name=${name}&staff_sn=${workNum}&dep_name=${departMent}`
        }else{
            window.query_time = null
        }
    })
    /**
     *全选的功能
     */
    $('#checkAll').on('click',function(){
        var checkboxs =$('input[type=checkbox]:not("#checkAll")');
        for(var i=0;i<checkboxs.length;i++){
            var checkbox=checkboxs[i];
            checkbox.checked=this.checked;
        }
    })
    $('#table_table').on('click','input[type=checkbox]:not("#checkAll")',function(){
        "use strict";
        var isCheckedAll = true;
        var checkboxs =$('input[type=checkbox]:not("#checkAll")');
        for (var i = 0; i < checkboxs.length; i++) {
            if (!checkboxs[i].checked) {
                isCheckedAll = false;
                break;
            }
        }
        $('#checkAll')[0].checked = isCheckedAll;
    })

    /*当点击添加按钮时*/
    $('.operation_btn').on('click','a',function(e){
        e.preventDefault();
        if( $(this).html() == '添加' ){
            let add_people = $(this).attr('href');
            $(`[lll=${add_people}]`).addClass('active');
            let htmls = '';
            $.ajax({
                url:'http://jk.com/Admin/Pay/getStaffName',
                type:'get',
                success:function(data){
                    for(var i=0;i<data.length;i++){
                        htmls += `
                            <option value="${data[i].id}" data-dep="${data[i].dep_name}">${data[i].staff_name}</option>
                        `
                    }
                    $(`[lll=${add_people}]`).find('[add_name="add_name"]').html(htmls)
                }
            })
            $.ajax({
                url:'http://jk.com/Admin/Pay/addPay',
                type:'get',
                success:function(data){
                    let datas = data.data
                    if(datas.shebao.is_cal==0){
                        console.log('不计算啦')
                    }else{
                        console.log('计算啦')
                        $(`[lll='add_people']`).find('[add_name="add_Insurance"]').attr('readonly',true)
                    }

                    if(datas.gjj.is_cal==0){
                    }else{
                        $(`[lll='add_people']`).find('[add_name="add_fund"]').attr('readonly',true)
                    }
                }
            })
        }
        if( $(this).html() == '批量删除' ){
            var checkboxs =$('input[type=checkbox]:not("#checkAll")');
            var len = 0;
            for (var i = 0; i < checkboxs.length; i++) {
                if (checkboxs[i].checked) {
                    continue
                }else{
                    len++
                }
            }
            if(len == checkboxs.length){
                $('#yz_modal').html('您还没有选择人员！')
                $('#yz_modal').addClass('active')
                tipShow()
                return
            }
            let _delete = $(this).attr('href');
            $(_delete).addClass('active')
        }
        if( $(this).html() == '批量导入' ){
            let showbox_id = $(this).attr('href');
            $(showbox_id).addClass('active')
        }
    })
    $(`[lll='add_people']`).find('[add_name="add_name"]').change(function(){
        let dep = $(this).children('option:selected').attr('data-dep')
        $(`[lll='add_people']`).find('[add_name="add_departMent"]').val(dep)
    })
    $(`[lll='add_people']`).find('[add_name="add_baseSalary"]').change(function(){
        let add_baseSalary = $(this).val()
        $.ajax({
            url:'http://jk.com/Admin/Pay/addPay',
            type:'get',
            success:function(data){
                let datas = data.data
                if(datas.shebao.is_cal == 0){
                }else{
                    $(`[lll='add_people']`).find('[add_name="add_Insurance"]').attr('readonly',true)
                    let p_yanglao = parseFloat(datas.shebao.p_bili.yanglao)/100;
                    let p_yiliao = parseFloat(datas.shebao.p_bili.yiliao)/100;
                    let p_shiye = parseFloat(datas.shebao.p_bili.shiye)/100;
                    let p_gongshang = parseFloat(datas.shebao.p_bili.gongshang)/100;
                    let p_shengyu = parseFloat(datas.shebao.p_bili.shengyu)/100;
                    let p_jin = parseFloat(datas.shebao.p_bili.jin)/100;
                    let c_yanglao = parseFloat(datas.shebao.c_bili.yanglao)/100;
                    let c_yiliao = parseFloat(datas.shebao.c_bili.yiliao)/100;
                    let c_shiye = parseFloat(datas.shebao.c_bili.shiye)/100;
                    let c_gongshang = parseFloat(datas.shebao.c_bili.gongshang)/100;
                    let c_shengyu = parseFloat(datas.shebao.c_bili.shengyu)/100;
                    let c_jin = parseFloat(datas.shebao.c_bili.jin)/100;

                    let InsuranceVal,low_base=parseFloat(datas.shebao.base.low),high_base=parseFloat(datas.shebao.base.high);
                    if(add_baseSalary<low_base){
                        InsuranceVal = ((low_base*p_yanglao)+(low_base*p_yiliao)+(low_base*p_shiye)+(low_base*p_gongshang)+(low_base*p_shengyu)+(low_base*p_jin)+(low_base*c_yanglao)+(low_base*c_yiliao)+(low_base*c_shiye)+(low_base*c_gongshang)+(low_base*c_shengyu)+(low_base*c_jin)).toFixed(2)
                    }else if(add_baseSalary>high_base){
                        InsuranceVal = ((high_base*p_yanglao)+(high_base*p_yiliao)+(high_base*p_shiye)+(high_base*p_gongshang)+(high_base*p_shengyu)+(high_base*p_jin)+(high_base*c_yanglao)+(high_base*c_yiliao)+(high_base*c_shiye)+(high_base*c_gongshang)+(high_base*c_shengyu)+(high_base*c_jin)).toFixed(2)
                    }else{
                        InsuranceVal = ((add_baseSalary*p_yanglao)+(add_baseSalary*p_yiliao)+(add_baseSalary*p_shiye)+(add_baseSalary*p_gongshang)+(add_baseSalary*p_shengyu)+(add_baseSalary*p_jin)+(add_baseSalary*c_yanglao)+(add_baseSalary*c_yiliao)+(add_baseSalary*c_shiye)+(add_baseSalary*c_gongshang)+(add_baseSalary*c_shengyu)+(add_baseSalary*c_jin)).toFixed(2)
                    }
                    $(`[lll='add_people']`).find('[add_name="add_Insurance"]').val(InsuranceVal)
                }

                if(datas.gjj.is_cal == 0){
                }else{
                    $(`[lll='add_people']`).find('[add_name="add_fund"]').attr('readonly',true)
                    let p_yanglao = parseFloat(datas.shebao.p_bili.yanglao)/100;
                    let p_yiliao = parseFloat(datas.shebao.p_bili.yiliao)/100;
                    let p_shiye = parseFloat(datas.shebao.p_bili.shiye)/100;
                    let p_gongshang = parseFloat(datas.shebao.p_bili.gongshang)/100;
                    let p_shengyu = parseFloat(datas.shebao.p_bili.shengyu)/100;
                    let p_jin = parseFloat(datas.shebao.p_bili.jin)/100;
                    let c_yanglao = parseFloat(datas.shebao.c_bili.yanglao)/100;
                    let c_yiliao = parseFloat(datas.shebao.c_bili.yiliao)/100;
                    let c_shiye = parseFloat(datas.shebao.c_bili.shiye)/100;
                    let c_gongshang = parseFloat(datas.shebao.c_bili.gongshang)/100;
                    let c_shengyu = parseFloat(datas.shebao.c_bili.shengyu)/100;
                    let c_jin = parseFloat(datas.shebao.c_bili.jin)/100;

                    let fundVal,low_base=parseFloat(datas.gjj.base.low),high_base=parseFloat(datas.gjj.base.high);
                    if(add_baseSalary<low_base){
                        fundVal = ((low_base*p_yanglao)+(low_base*p_yiliao)+(low_base*p_shiye)+(low_base*p_gongshang)+(low_base*p_shengyu)+(low_base*p_jin)+(low_base*c_yanglao)+(low_base*c_yiliao)+(low_base*c_shiye)+(low_base*c_gongshang)+(low_base*c_shengyu)+(low_base*c_jin)).toFixed(2)
                    }else if(add_baseSalary>high_base){
                        fundVal = ((high_base*p_yanglao)+(high_base*p_yiliao)+(high_base*p_shiye)+(high_base*p_gongshang)+(high_base*p_shengyu)+(high_base*p_jin)+(high_base*c_yanglao)+(high_base*c_yiliao)+(high_base*c_shiye)+(high_base*c_gongshang)+(high_base*c_shengyu)+(high_base*c_jin)).toFixed(2)
                    }else{
                        fundVal = ((add_baseSalary*p_yanglao)+(add_baseSalary*p_yiliao)+(add_baseSalary*p_shiye)+(add_baseSalary*p_gongshang)+(add_baseSalary*p_shengyu)+(add_baseSalary*p_jin)+(add_baseSalary*c_yanglao)+(add_baseSalary*c_yiliao)+(add_baseSalary*c_shiye)+(add_baseSalary*c_gongshang)+(add_baseSalary*c_shengyu)+(add_baseSalary*c_jin)).toFixed(2)
                    }
                    $(`[lll='add_people']`).find('[add_name="add_fund"]').val(fundVal)
                }
            }
        })
    })
    // 批量删除
    $('.delete_tip_btn_box').on('click','button',function(){
        "use strict";
        let delete_arr = [];
        if($(this).html() == '确认'){
            let checkboxs =$('#table_table input[type=checkbox]:not("#checkAll")');
            for (let i = 0; i < checkboxs.length; i++) {
                if (checkboxs[i].checked) {
                    delete_arr.push( $(checkboxs[i]).closest('tr[data-index]').attr('data-index') )
                }else{
                    continue;
                }
            }
            $.ajax({
                url:'http://jk.com/Admin/Pay/multiDelPay',
                type:'post',
                data:{
                    pay_id: delete_arr
                },
                success:function(data){
                    if(data.code==1){
                        for(let r = 0; r < delete_arr.length; r++){
                            $('#table_table').children('tbody').children(`[data-index=${delete_arr[r]}]`).remove();
                        }
                        $('#delete').removeClass('active')
                    }
                }
            })
        }else{
            $('#delete').removeClass('active')
        }

    })

    // 当点击编辑按钮时
    $('#table_table').on('click','.edit_table',function(e){
        e.preventDefault();
        let operation = $(this).attr('href');
        let operation_id = $(this).closest('tr').attr('data-index');
        if( operation == 'edit_people'){
            let html = '';
            $.ajax({
                url:'http://jk.com/Admin/Pay/getStaffName',
                type:'get',
                success:function(data){
                    for(var i=0;i<data.length;i++){
                        html += `
                            <option value="${data[i].id}" data-dep="${data[i].dep_name}">${data[i].staff_name}</option>
                        `
                    }
                    $(`[lll=${operation}]`).find('[add_name="edit_name"]').html(html)
                }
            })
            $.ajax({
                url:'http://jk.com/Admin/Pay/addPay',
                type:'get',
                success:function(data){
                    let datas = data.data
                    if(datas.shebao.is_cal==0){
                        console.log('不计算啦')
                    }else{
                        console.log('计算啦')
                        $(`[lll='add_people']`).find('[add_name="add_Insurance"]').attr('readonly',true)
                    }

                    if(datas.gjj.is_cal==0){
                    }else{
                        $(`[lll='add_people']`).find('[add_name="add_fund"]').attr('readonly',true)
                    }
                }
            })
            $.ajax({
                url:'http://jk.com/Admin/Pay/editPay',
                type:'get',
                data:{
                    id:operation_id
                },
                success:function(data){
                    console.log(data.data)
                    let datas = data.data
                    $(`[lll=${operation}]`).find(`[add_name='edit_time']`).val(datas.pay_time)
                    $(`[lll=${operation}]`).find(`[add_name='edit_name']`).val(datas.staff_id)
                    $(`[lll=${operation}]`).find(`[add_name='edit_departMent']`).val(datas.dep_name)
                    $(`[lll=${operation}]`).find(`[add_name='edit_baseSalary']`).val(datas.base_money)
                    $(`[lll=${operation}]`).find(`[add_name='edit_bonus']`).val(datas.prize)
                    $(`[lll=${operation}]`).find(`[add_name='edit_Insurance']`).val(datas.ins)
                    $(`[lll=${operation}]`).find(`[add_name='edit_fund']`).val(datas.jin)

                    window.sessionStorage['operation_pid']=datas.staff_id
                }
            })
            window.sessionStorage['operation_id']=operation_id

            $(`[lll=${operation}]`).addClass('active');
        }
    })
    $(`[lll='edit_people']`).find('[add_name="edit_name"]').change(function(){
        let dep = $(this).children('option:selected').attr('data-dep')
        $(`[lll='edit_people']`).find('[add_name="edit_departMent"]').val(dep)
    })
    $(`[lll='edit_people']`).find('[add_name="edit_baseSalary"]').change(function(){
        let edit_baseSalary = $(this).val()
        $.ajax({
            url:'http://jk.com/Admin/Pay/addPay',
            type:'get',
            success:function(data){
                let datas = data.data
                if(datas.shebao.is_cal == 0){
                }else{
                    $(`[lll='edit_people']`).find('[add_name="edit_Insurance"]').attr('readonly',true)
                    let p_yanglao = parseFloat(datas.shebao.p_bili.yanglao)/100;
                    let p_yiliao = parseFloat(datas.shebao.p_bili.yiliao)/100;
                    let p_shiye = parseFloat(datas.shebao.p_bili.shiye)/100;
                    let p_gongshang = parseFloat(datas.shebao.p_bili.gongshang)/100;
                    let p_shengyu = parseFloat(datas.shebao.p_bili.shengyu)/100;
                    let p_jin = parseFloat(datas.shebao.p_bili.jin)/100;
                    let c_yanglao = parseFloat(datas.shebao.c_bili.yanglao)/100;
                    let c_yiliao = parseFloat(datas.shebao.c_bili.yiliao)/100;
                    let c_shiye = parseFloat(datas.shebao.c_bili.shiye)/100;
                    let c_gongshang = parseFloat(datas.shebao.c_bili.gongshang)/100;
                    let c_shengyu = parseFloat(datas.shebao.c_bili.shengyu)/100;
                    let c_jin = parseFloat(datas.shebao.c_bili.jin)/100;

                    let InsuranceVal,low_base=parseFloat(datas.shebao.base.low),high_base=parseFloat(datas.shebao.base.high);
                    if(edit_baseSalary<low_base){
                        InsuranceVal = ((low_base*p_yanglao)+(low_base*p_yiliao)+(low_base*p_shiye)+(low_base*p_gongshang)+(low_base*p_shengyu)+(low_base*p_jin)+(low_base*c_yanglao)+(low_base*c_yiliao)+(low_base*c_shiye)+(low_base*c_gongshang)+(low_base*c_shengyu)+(low_base*c_jin)).toFixed(2)
                    }else if(edit_baseSalary>high_base){
                        InsuranceVal = ((high_base*p_yanglao)+(high_base*p_yiliao)+(high_base*p_shiye)+(high_base*p_gongshang)+(high_base*p_shengyu)+(high_base*p_jin)+(high_base*c_yanglao)+(high_base*c_yiliao)+(high_base*c_shiye)+(high_base*c_gongshang)+(high_base*c_shengyu)+(high_base*c_jin)).toFixed(2)
                    }else{
                        InsuranceVal = ((edit_baseSalary*p_yanglao)+(edit_baseSalary*p_yiliao)+(edit_baseSalary*p_shiye)+(edit_baseSalary*p_gongshang)+(edit_baseSalary*p_shengyu)+(edit_baseSalary*p_jin)+(edit_baseSalary*c_yanglao)+(edit_baseSalary*c_yiliao)+(edit_baseSalary*c_shiye)+(edit_baseSalary*c_gongshang)+(edit_baseSalary*c_shengyu)+(edit_baseSalary*c_jin)).toFixed(2)
                    }
                    $(`[lll='edit_people']`).find('[add_name="edit_Insurance"]').val(InsuranceVal)
                }

                if(datas.gjj.is_cal == 0){
                }else{
                    $(`[lll='ediy_people']`).find('[add_name="edit_fund"]').attr('readonly',true)
                    let p_yanglao = parseFloat(datas.shebao.p_bili.yanglao)/100;
                    let p_yiliao = parseFloat(datas.shebao.p_bili.yiliao)/100;
                    let p_shiye = parseFloat(datas.shebao.p_bili.shiye)/100;
                    let p_gongshang = parseFloat(datas.shebao.p_bili.gongshang)/100;
                    let p_shengyu = parseFloat(datas.shebao.p_bili.shengyu)/100;
                    let p_jin = parseFloat(datas.shebao.p_bili.jin)/100;
                    let c_yanglao = parseFloat(datas.shebao.c_bili.yanglao)/100;
                    let c_yiliao = parseFloat(datas.shebao.c_bili.yiliao)/100;
                    let c_shiye = parseFloat(datas.shebao.c_bili.shiye)/100;
                    let c_gongshang = parseFloat(datas.shebao.c_bili.gongshang)/100;
                    let c_shengyu = parseFloat(datas.shebao.c_bili.shengyu)/100;
                    let c_jin = parseFloat(datas.shebao.c_bili.jin)/100;

                    let fundVal,low_base=parseFloat(datas.gjj.base.low),high_base=parseFloat(datas.gjj.base.high);
                    if(edit_baseSalary<low_base){
                        fundVal = ((low_base*p_yanglao)+(low_base*p_yiliao)+(low_base*p_shiye)+(low_base*p_gongshang)+(low_base*p_shengyu)+(low_base*p_jin)+(low_base*c_yanglao)+(low_base*c_yiliao)+(low_base*c_shiye)+(low_base*c_gongshang)+(low_base*c_shengyu)+(low_base*c_jin)).toFixed(2)
                    }else if(edit_baseSalary>high_base){
                        fundVal = ((high_base*p_yanglao)+(high_base*p_yiliao)+(high_base*p_shiye)+(high_base*p_gongshang)+(high_base*p_shengyu)+(high_base*p_jin)+(high_base*c_yanglao)+(high_base*c_yiliao)+(high_base*c_shiye)+(high_base*c_gongshang)+(high_base*c_shengyu)+(high_base*c_jin)).toFixed(2)
                    }else{
                        fundVal = ((edit_baseSalary*p_yanglao)+(edit_baseSalary*p_yiliao)+(edit_baseSalary*p_shiye)+(edit_baseSalary*p_gongshang)+(edit_baseSalary*p_shengyu)+(edit_baseSalary*p_jin)+(edit_baseSalary*c_yanglao)+(edit_baseSalary*c_yiliao)+(edit_baseSalary*c_shiye)+(edit_baseSalary*c_gongshang)+(edit_baseSalary*c_shengyu)+(edit_baseSalary*c_jin)).toFixed(2)
                    }
                    $(`[lll='edit_people']`).find('[add_name="edit_fund"]').val(fundVal)
                }
            }
        })
    })
    // 确认按钮点击时
    $('#add_btn').click(function(){
        let time = window.add_time;
        let name_id = $(this).closest('[lll]').find('[add_name=add_name]').val();
        let name = $(this).closest('[lll]').find('[add_name=add_name] option:selected').html();
        let department = $(this).closest('[lll]').find('[add_name=add_departMent]').val();
        let baseSalary = $(this).closest('[lll]').find('[add_name=add_baseSalary]').val();
        let bonus = $(this).closest('[lll]').find('[add_name=add_bonus]').val();
        let Insurance = $(this).closest('[lll]').find('[add_name=add_Insurance]').val();
        let fund = $(this).closest('[lll]').find('[add_name=add_fund]').val();

        if(time == '' || name == '' || department == '' || baseSalary == '' ){
            $('#yz_modal').html('您有内容没有填写完整！')
            $('#yz_modal').addClass('active')
            tipShow()
            return
        }
        let that = $(this)
        $.ajax({
            url:'http://jk.com/Admin/Pay/addPay',
            type:'post',
            data:{
                pay_year: window.add_time_year,
                pay_month: window.add_time_month,
                staff_id: name_id,
                base_money: baseSalary,
                prize: bonus,
                ins: Insurance,
                jin: fund
            },
            success:function(data){
                console.log(data)
                if(data.code==1){
                    var peopleTableHTML = $('#table_table').children('tbody').html()
                    peopleTableHTML += `
                    <tr data-index="${data.id}">
                            <td><input type="checkbox" class="checkboxStyle"></td>
                            <td data-name="edit_time">${time}</td>
                            <td data-name="edit_name">${name}</td>
                            <td data-name="edit_num">123</td>
                            <td data-name="edit_departMent">${department}</td>
                            <td data-name="edit_baseSalary">${baseSalary}</td>
                            <td data-name="edit_bonus">${bonus}</td>
                            <td data-name="edit_Insurance">${Insurance}</td>
                            <td data-name="edit_fund">${fund}</td>
                            <td style><a href="edit_people" class="edit_table">编辑</a></td>
                        </tr>
            `
                    $('#table_table').children('tbody').html(peopleTableHTML)

                    that.closest('[lll]').find('[add_name=add_time]').val('')
                    that.closest('[lll]').find('[add_name="add_name"]').val('')
                    that.closest('[lll]').find('[add_name="add_departMent"]').val('')
                    that.closest('[lll]').find('[add_name=add_baseSalary]').val('')
                    that.closest('[lll]').find('[add_name=add_bonus]').val('')
                    that.closest('[lll]').find('[add_name=add_Insurance]').val('')
                    that.closest('[lll]').find('[add_name=add_fund]').val('')
                }else{
                    $('#yz_modal').html(data.msg)
                    $('#yz_modal').addClass('active')
                    tipShow()
                }
            }
        })
        $(this).parent().parent().removeClass('active')
        $(this).closest('[lll]').removeClass('active')
    })
    // 确认并新增按钮点击时
    $('#add_AddNew_btn').click(function(){
        let time = window.add_time;
        let name_id = $(this).closest('[lll]').find('[add_name=add_name]').val();
        let name = $(this).closest('[lll]').find('[add_name=add_name] option:selected').html();
        let department = $(this).closest('[lll]').find('[add_name=add_departMent]').val();
        let baseSalary = $(this).closest('[lll]').find('[add_name=add_baseSalary]').val();
        let bonus = $(this).closest('[lll]').find('[add_name=add_bonus]').val();
        let Insurance = $(this).closest('[lll]').find('[add_name=add_Insurance]').val();
        let fund = $(this).closest('[lll]').find('[add_name=add_fund]').val();

        if(time == '' || name == '' || department == '' || baseSalary == '' ){
            $('#yz_modal').html('您有内容没有填写完整！')
            $('#yz_modal').addClass('active')
            tipShow()
            return
        }
        let that = $(this)
        $.ajax({
            url:'http://jk.com/Admin/Pay/addPay',
            type:'post',
            data:{
                pay_year: window.add_time_year,
                pay_month: window.add_time_month,
                staff_id: name_id,
                base_money: baseSalary,
                prize: bonus,
                ins: Insurance,
                jin: fund
            },
            success:function(data){
                console.log(data)
                if(data.code==1){
                    var peopleTableHTML = $('#table_table').children('tbody').html()
                    peopleTableHTML += `
                    <tr data-index="${data.id}">
                            <td><input type="checkbox" class="checkboxStyle"></td>
                            <td data-name="edit_time">${time}</td>
                            <td data-name="edit_name">${name}</td>
                            <td data-name="edit_num">123</td>
                            <td data-name="edit_departMent">${department}</td>
                            <td data-name="edit_baseSalary">${baseSalary}</td>
                            <td data-name="edit_bonus">${bonus}</td>
                            <td data-name="edit_Insurance">${Insurance}</td>
                            <td data-name="edit_fund">${fund}</td>
                            <td style><a href="edit_people" class="edit_table">编辑</a></td>
                        </tr>
            `
                    $('#table_table').children('tbody').html(peopleTableHTML)

                    that.closest('[lll]').find('[add_name=add_time]').val('')
                    that.closest('[lll]').find('[add_name=add_name]').val('')
                    that.closest('[lll]').find('[add_name=add_departMent]').val('')
                    that.closest('[lll]').find('[add_name=add_baseSalary]').val('')
                    that.closest('[lll]').find('[add_name=add_bonus]').val('')
                    that.closest('[lll]').find('[add_name=add_Insurance]').val('')
                    that.closest('[lll]').find('[add_name=add_fund]').val('')
                }
            }
        })
    })
    // 保存按钮点击时
    $('#save_btn').click(function(){
        if( $(this).html() == '保存' ){
            let operation_id = window.sessionStorage['operation_id']
            let operation_pid = window.sessionStorage['operation_pid']

            let time = $(this).closest('[lll]').find('[add_name=edit_time]').val()
            let timer = time.split('-');
            for(var timeri=0;timeri<timer.length;timeri++){
                var time_year = timer[0]
                var time_month = timer[1]
            }

            let name_id = $(this).closest('[lll]').find('[add_name=edit_name]').val()
            let name = $(this).closest('[lll]').find('[add_name=edit_name] option:selected').text()
            let department = $(this).closest('[lll]').find('[add_name=edit_departMent]').val()
            let baseSalary = $(this).closest('[lll]').find('[add_name=edit_baseSalary]').val()
            let bonus = $(this).closest('[lll]').find('[add_name=edit_bonus]').val()
            let Insurance = $(this).closest('[lll]').find('[add_name=edit_Insurance]').val()
            let fund = $(this).closest('[lll]').find('[add_name=edit_fund]').val()

            $.ajax({
                url:'http://jk.com/Admin/Pay/editPay',
                type:'post',
                data:{
                    id:operation_id,
                    pay_year:time_year,
                    pay_month:time_month,
                    staff_id: operation_pid,
                    base_money: baseSalary,
                    prize: bonus,
                    ins: Insurance,
                    jin: fund
                },
                success:function(data){
                    console.log(data)
                    if(data.code==1){
                        var tableHTML = $('#table_table').children('tbody').find(`[data-index=${operation_id}]`)

                        tableHTML.children('[data-name=edit_time]').html(time)
                        tableHTML.children('[data-name=edit_name]').html(name)
                        tableHTML.children('[data-name=edit_departMent]').html(department)
                        tableHTML.children('[data-name=edit_baseSalary]').html(baseSalary)
                        tableHTML.children('[data-name=edit_bonus]').html(bonus)
                        tableHTML.children('[data-name=edit_Insurance]').html(Insurance)
                        tableHTML.children('[data-name=edit_fund]').html(fund)
                    }
                }
            })
        }
        $(this).parent().parent().removeClass('active')
    })
    // 取消按钮点击时
    $('.button_list').on('click','button',function(){
        if($(this).hasClass('cancel_btn')){
            $(this).closest('[lll]').removeClass('active')
        }
    })

// 上传文件
    $('#file_upload').change(function (e) {
        $(this).siblings('.import_tip_btn_box').find('button').removeClass('btn-grey').addClass('btn-success')
    })
    $('#import').find('button').click(function(e){
        "use strict";
        e.preventDefault()
        if($(this).hasClass('btn-success')){
            if($(this).html()=='确定导入'){
                var formData = new FormData($("#file_form")[0]);
                $.ajax({
                    async : false,
                    cache : false,
                    type : "post",
                    data : formData,
                    url : 'http://jk.com/Admin/Knowledge/importKnow',
                    dataType : 'json',
                    contentType: false, //必须
                    processData: false, //必须
                    success : function(data) {
                        console.log(data);
                        if(data.code==1){
                            $('#import').removeClass('active')
                        }else{
                            // console.log(222)
                            // console.log($('#yz_modal').html())
                            $('#yz_modal').html(data.msg)
                            $('#yz_modal').addClass('active')
                            tipShow()
                        }
                    }
                })
            }
        }

    })

    // 弹出来的小框框
    function tipShow(){
        window.tipBox = setTimeout(function(){
            // $('#yz_modal').removeClass('active')
            // $('#yz_modal').addClass('fadeOut')
            $('#yz_modal').removeClass('active')
            clearTimeout(tipBox)
        },2000)
    }

    //当点击区域不在导入弹框中时则关闭弹框
    $(document).click(function(e){
        let $this = $(e.target);
        if($this.closest('#import').length==0){
            if($this.attr('href') != '#import' && $this.children().attr('href') != '#import'){
                $('#import').removeClass('active');
            }
        }
    })

})